package panel.viewSpots
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.geom.Rectangle;
	
	import assists.Lang;
	import assists.SizeManager;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import inerface.IViewSpotPanel;
	
	import main.ClientConstants;
	
	public class ViewSpotPanel extends Sprite implements IViewSpotPanel
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var _spotPicGroup:ViewSpotPicGroup;
		private var _openDetailFunc:Function;
		public function ViewSpotPanel()
		{
			super();
		}
		
		public function init(stage:Stage,loader:ResourceLoader,lang:Lang,uri:URI = null):void
		{
			_stage  = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
		}
		
		public function show(dataList:Array):void
		{
			_spotPicGroup = new ViewSpotPicGroup();
			_spotPicGroup.onOpenDetail = _openDetailFunc;
			_spotPicGroup.init(_stage,_loader,_lang,_uri);
			_spotPicGroup.showSpotList(dataList);
			this.addChild(_spotPicGroup);
			if(_spotPicGroup.height < _stage.stageHeight - SizeManager.guideHeight) return;
			if(ClientConstants.SLIDE_POS.memory)
			{
				ClientConstants.SLIDE_POS.memory = false;	
				_spotPicGroup.y =  ClientConstants.SLIDE_POS.pos;
				StaticSlide.beginSlide(_spotPicGroup,_stage,new Rectangle(0,-_spotPicGroup.height + _stage.stageHeight - SizeManager.UpGuideHeight - SizeManager.donwGuideHeight,0,_spotPicGroup.height- _stage.stageHeight + SizeManager.UpGuideHeight + SizeManager.donwGuideHeight));
			}else
			{
			_spotPicGroup.y = SizeManager.UpGuideHeight;
				StaticSlide.beginSlide(_spotPicGroup,_stage,new Rectangle(0,_spotPicGroup.y,0,-_spotPicGroup.height + SizeManager.guideHeight),_spotPicGroup.y);
			}
		}
		
		public function set openDetail(value:Function):void
		{
			_openDetailFunc = value;
		}
		
		public function clear():void
		{
			ClientConstants.SLIDE_POS = {pos:_spotPicGroup.y};
			if(_spotPicGroup){
				StaticSlide.clear(_spotPicGroup);
				_spotPicGroup.clear();
				this.removeChild(_spotPicGroup);
				_spotPicGroup = null;
			}
		}
		
	}
}